﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software component that provide 
// support for localization. This library enable you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace SLS.ExClassLib.Loc
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Windows;

    /// <summary>
    /// Implements a class that contains informations about the engine.
    /// </summary>
    public class LocalizationEngineInfo : INotifyPropertyChanged
    {
        //Events

        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        //Fields

        private bool _isLocalizing = false;

        //Properties

        /// <summary>
        /// Gets true if the engine is localizing false otherwise.
        /// </summary>
        public bool IsLocalizing
        {
            get 
            { 
                return this._isLocalizing; 
            }
            private set 
            {
                if (this._isLocalizing != value)
                {
                    this._isLocalizing = value;
                    this.OnPropertyChange("IsLocalizing");
                }
            }
        }

        //Methods

        /// <summary>
        /// Assigns at the property <see cref="LocalizationEngineInfo.IsLocalizing"/> the input <paramref name="vale"/>.
        /// </summary>
        /// <param name="value"></param>
        internal void SetIsLocalizing(bool value) 
        {
            this.IsLocalizing = value;
        }

        /// <summary>
        /// Publishes the PropertyChanged event.
        /// </summary>
        /// <param name="propertyName"></param>
        protected internal void OnPropertyChange(String propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
#if SILVERLIGHT
                Action action = new Action(() =>
                {
                    handler(this, new PropertyChangedEventArgs(propertyName));
                });
                Deployment.Current.Dispatcher.BeginInvoke(action);
#else
                handler(this, new PropertyChangedEventArgs(propertyName));
#endif
            }
        }
    }
}